<?php

namespace App\Http\Requests\Admin;

use App\Models\Permission;
use Illuminate\Foundation\Http\FormRequest;

class PermissionRequest extends FormRequest
{
    /**
     * Determine if the user is authorized to make this request.
     *
     * @return bool
     */
    public function authorize()
    {
        return true;
    }

    /**
     * Get the validation rules that apply to the request.
     *
     * @return array
     */
    public function rules()
    {
        return [
            'permission_name'=>'required|max:30|regex:/^[\x{4e00}-\x{9fa5}A-Za-z0-9-_]+$/u',//应该补充唯一验证
			'pid'=> [
				'required',
				'integer',
				'max:1000',
				function ($attribute, $value, $fail){
					if ((int)$value != '0') {
						$checkExist = Permission::find($value);
						if ( ! $checkExist) {
							return $fail('父类不存在');
						}
					}
				},
			],

        ];
    }
}
